// ADS Point lighting Shader

#version 130

in vec4 vertex;
in vec4 normal;

in mat4 mMatrix;
in mat4 nMatrix;

uniform mat4 vpMatrix;
uniform vec4 lightPos;
uniform vec4 cameraPos;

uniform vec4 lightAmbient;
uniform vec4 lightDiffuse;
uniform vec4 lightSpecular;

in vec4 vmat_ambient;
in vec4 vmat_diffuse;
in vec4 vmat_specular;
in float vmat_shininess;

out vec4 fmat_ambient;
out vec4 fmat_diffuse;
out vec4 fmat_specular;
out float fmat_shininess;

out vec3 fNormal;
out vec3 fLightDir;
out vec3 fCameraDir;

void main(void) 
{
  fNormal = (nMatrix * normal).xyz;

  vec4 transformedPos = mMatrix * vertex;

  fLightDir = normalize(lightPos.xyz - transformedPos.xyz);
  fCameraDir = normalize(cameraPos.xyz - transformedPos.xyz);

  gl_Position = vpMatrix * transformedPos;
  
  // copy data to fragment stage
  fmat_ambient = vmat_ambient*lightAmbient;
  fmat_diffuse = vmat_diffuse*lightDiffuse;
  fmat_specular = vmat_specular*lightSpecular;
  fmat_shininess = vmat_shininess;
}
